package com.lzs.bootsafety.common.util;

import com.lzs.bootsafety.business.sys.entity.SysMenu;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanshi liu
 * @date 2020/03/24
 * @website www.jhmsona.cn
 */
public class MenuTree {
    public  static List<SysMenu> buildTree(List<SysMenu> nodes,Long menu_Id){
        List<SysMenu> sysMenus = new ArrayList<SysMenu>();
        for (SysMenu sysMenu: nodes) {
            if (menu_Id == sysMenu.getParentId()){
                sysMenu.setChildren(buildTree(nodes,sysMenu.getMenuId()));
                sysMenus.add(sysMenu);
            }
        }
        return sysMenus;
    }

    public  static List<SysMenu> buildTreeNormal(List<SysMenu> nodes,Long menu_Id){
        List<SysMenu> sysMenus = new ArrayList<SysMenu>();
        for (SysMenu sysMenu: nodes) {
            if(sysMenu.getStatus()=="0" || "0".equals(sysMenu.getStatus())){
                if (menu_Id == sysMenu.getParentId()){
                    sysMenu.setChildren(buildTreeNormal(nodes,sysMenu.getMenuId()));
                    sysMenus.add(sysMenu);
                }
            }
        }
        return sysMenus;
    }
}
